package com.njegovanobradovic.pages.admin;

import java.util.List;

import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.hibernate.annotations.CommitAfter;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.njegovanobradovic.entities.Media;
import com.njegovanobradovic.so.Delete;
import com.njegovanobradovic.so.GetAll;

public class Library {
	@Property
	private Media media;
	@Inject
	private GetAll<Media> getAllMedia;
	
	public List<Media> getMediaList(){
		getAllMedia.setSearchForType(Media.class);
		return getAllMedia.execute();
	}
	
	@Inject
	private Delete<Media> deleteMedia;
	@CommitAfter
	public void onDelete(Long id) {
		try {
			deleteMedia.setId(id);
			deleteMedia.setSearchForType(Media.class);
			System.out.println(deleteMedia.execute());
		} catch (Exception e) {
			System.out.println("**********************Error on delete********************\n"+e);
		}
	}
}
